import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:well_known/config/configs.dart';

import '../home_index/home_index.dart';
import '../home_mine/home_mine.dart';
import '../home_second/home_second.dart';
import 'home_cubit.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (context) => HomeCubit(),
      child: BlocBuilder<HomeCubit, HomeState>(
        builder: (BuildContext context, HomeState state) {
          return SafeArea(
            top: false,
            child: Scaffold(
              body: const [HomeIndexPage(), HomeSecondPage(), HomeMinePage()][state.currentIndex],
              floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
              //悬浮按钮
              floatingActionButton: SizedBox(
                height: 80,
                width: 80,
                child: FloatingActionButton(
                  shape: CircleBorder(),
                  child: const Icon(Icons.add),
                  onPressed: () {
                    Navigator.pushNamed(context, Pages.entryAdd.toString());
                  },
                ),
              ),
              bottomNavigationBar: BottomAppBar(
                shape: CircularNotchedRectangle(),
                child: Row(
                  children: [
                    Expanded(child: IconButton(icon: Icon(Icons.home), onPressed: () {})),
                    Expanded(child: Spacer()),
                    Expanded(child: IconButton(icon: Icon(Icons.shop), onPressed: () {})),
                  ],
                ),
              ),
            ),
          );
        },
      ),
    );
  }
}
